home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / COMMUNIC / BULLETIN / 0157.ZIP / GENERIC.ASM < prev    next >
Assembly Source File  |  1985-11-13  |  5KB  |  239 lines

  1. title Generic Fido Driver
  2. name generic
  3.  
  4. comment ~
  5.  
  6.         updated 13 Nov 85
  7.     T. Jennings 12 July 85
  8.  
  9.     This is a sample generic driver for
  10. FIDO_GEN, seyup for the IBM PC. You will
  11. of course have to rewrite it to fit your
  12. particular hardware; refer to GENERIC.DOC
  13. for details.
  14.  
  15.     This is a terminate stay resident
  16. program; install it by running it from
  17. AUTOEXEC.BAT, only once. Who knows what
  18. happens if you run it more than that. You 
  19. could of course make it a device driver,
  20. but these are easier to debug.
  21.  
  22. end comment -> ~
  23. ;
  24. ;Modem port equates: IBM PC type 8250. IBM PC
  25. ;COM2 is 2f8.
  26. ;
  27. BASE    equ    3f8h        ;COM1 base
  28.  
  29. MDATA    equ BASE + 0        ; modem data port 
  30. MLINE    equ BASE + 3        ; line control 
  31. MLSTAT    equ BASE + 5        ; line status 
  32. MCNTRL    equ BASE + 4        ; modem control 
  33. MSTAT    equ BASE + 6        ; modem status 
  34. MBAUDL    equ BASE + 0        ; baud rate low 
  35. MBAUDH    equ BASE + 1        ; baud rate high 
  36. INTENB    equ BASE + 1        ; int enb reg
  37. INTID    equ BASE + 2        ; interrupt ID
  38.  
  39. DLAB    equ    80h        ; divisor acc.
  40. RDA    equ    01h        ; Rx char ready
  41. TBE    equ    20h        ; Tx buff empty
  42. MODE    equ    03h        ; 8 bits no par 
  43. RTS    equ    2        ; RTS bit
  44. DTR    equ    1        ; DTR bit
  45. B300    equ    0180h        ; 300 baud 
  46. B1200    equ    0060h        ; 1200 baud 
  47. B2400    equ    0030h        ; 2400 baud
  48. B9600    equ    000ch        ; 9600 baud 
  49.  
  50. code segment byte public 'code'
  51. assume cs:code,ds:code
  52.  
  53.     org    100h
  54. ;
  55. ;All this part does is install the driver
  56. ;in INT 14 and return to DOS, leaving the
  57. ;driver installed in memory.
  58. ;
  59. main:    mov    dx,offset signon
  60.     mov    ah,9        ;print string
  61.     int    21h        ;call DOS
  62. ;
  63. ;Install our interrupt vector for INT 14.
  64. ;
  65.     mov    ah,25h        ;SET VECTOR
  66.     mov    al,14h        ;the int number
  67.     mov    dx,offset int14    ;the vector
  68.     int    21h        ;call DOS
  69. ;
  70. ;Calculate the paragraph address of our 
  71. ;program; this is (segment + 
  72. ;(ceiling endcode)) / 16
  73. ;
  74.     mov    dx,offset endcode
  75.     add    dx,15
  76.     shr    dx,1
  77.     shr    dx,1
  78.     shr    dx,1
  79.     shr    dx,1
  80. ;    mov    ax,cs        ;our segment
  81. ;    add    dx,ax        ;plus seg len
  82.     mov    al,0
  83.     mov    ah,31h        ;terminate
  84.     int    21h
  85.  
  86. signon    db 'Generic Fido Driver -- IBM PC COM1'
  87.     db 13,10,'T. Jennings 12 July 85'
  88.     db 13,10,'$'
  89. page
  90. ;
  91. ;This is the actual INT 14 dispatcher. Fido
  92. ;calls this via INT 14. See GENERIC.DOC for
  93. ;details on what each call is.
  94. ;
  95. ;AH = function
  96. ;AL = function argument
  97. ;DX = IO port
  98. ;
  99. int14:    push    ds        ;be nice 
  100.     push    bp        ;to the C code
  101.     mov    bx,cs
  102.     mov    ds,bx        ;set DS:
  103.  
  104.     mov    bl,ah        ;set to use
  105.     and    bx,7        ;jump table
  106.     add    bx,bx        ;word ptr
  107.     call    word ptr jmptbl[bx]
  108.  
  109.     pop    bp
  110.     pop    ds
  111.     iret
  112. ;
  113. ;The function jump table.
  114. ;
  115. jmptbl label word
  116.     dw    baud        ;AH = 0
  117.     dw    write        ;etc
  118.     dw    read
  119.     dw    status
  120.     dw    init
  121.     dw    uninit
  122.     dw    dodtr
  123.     dw    tick
  124. page
  125. ;
  126. ;Initialize the serial port. 
  127. ;
  128. init:    mov    dx,MLINE    ;set 8 data,
  129.     mov    al,MODE        ;no parity
  130.     out    dx,al
  131.  
  132.     mov    dx,MDATA    ;clear the UART
  133.     in    al,dx        ;of any garbage
  134.     in    al,dx        ;characters
  135.     in    al,dx
  136.     in    al,dx
  137.     ret
  138. ;
  139. ;Uninitialize the serial port. Not
  140. ;needed.
  141. ;
  142. uninit:    ret
  143. ;
  144. ;Set the baud rate as specified in AL. Since
  145. ;we do only NO PARITY and ONE STOP BIT, we
  146. ;can just mask off the rubbish.
  147. ;
  148. baud:    and    al,11100000b    ;strip it,
  149.     mov    bx,B300
  150.     cmp    al,01000000b    ;300
  151.     je    b1
  152.     mov    bx,B1200
  153.     cmp    al,10000000b    ;1200
  154.     je    b1
  155.     mov    bx,B2400    ;2400
  156.     cmp    al,10100000b
  157.     je    b1
  158.     mov    bx,B9600    ;else 9600
  159.  
  160. b1:    pushf            ;no ints 
  161.     cli            ;while fiddling
  162.     mov    dx,MLINE    ;set baud port
  163.     mov    al,DLAB+MODE    ;DLAB, 8 bits,
  164.     out    dx,al
  165.  
  166.     mov    dx,MBAUDL    ;low byte baud
  167.     mov    al,bl
  168.     out    dx,al
  169.  
  170.     mov    dx,MBAUDH    ;now high byte
  171.     mov    al,bh
  172.     out    dx,al
  173.  
  174.     mov    dx,MLINE    ;reset DLAB,
  175.     mov    al,MODE
  176.     out    dx,al        ;select data 
  177.     popf
  178.     ret
  179. page
  180. ;
  181. ;Read a byte from the serial port; wait if
  182. ;necessary.
  183. ;
  184. read:    call    status        ;wait for one,
  185.     and    ah,RDA
  186.     jz    read
  187.     mov    dx,MDATA    ;get data port,
  188.     in    al,dx        ;get data.
  189.     ret
  190. ;
  191. ;Write a byte from AL to the modem.
  192. ;
  193. write:    push    ax        ;save it,
  194. w1:    call    status        ;wait til
  195.     and    ah,TBE        ;ready,
  196.     jz    w1
  197.     pop    ax
  198.     mov    dx,MDATA    ;get data port,
  199.     out    dx,al        ;put data.
  200.     ret
  201. page
  202. ;
  203. ;Raise DTR if AL is nonzero, else lower it.
  204. ;
  205. dodtr:    cmp    al,0        ;see if zero
  206.     mov    al,RTS        ;clear DTR
  207.     je    d1        ;else ret it
  208.     mov    al,RTS + DTR
  209. d1:    mov    dx,MCNTRL
  210.     out    dx,al
  211.     ret
  212. ;
  213. ;Return status in AX.
  214. ;
  215. status:    mov    dx,MLSTAT
  216.     in    al,dx        ;line status
  217.     mov    ah,al        ;put in AH
  218.     mov    dx,MSTAT
  219.     in    al,dx        ;modem in AL
  220.     ret
  221. ;
  222. ;Return the timer tick information: the tick
  223. ;interval (mS per tick) in DX, the interrupt
  224. ;vector in AL (0 - 255) and the number of ticks
  225. ;per second in AH.
  226. ;
  227. tick:    mov    al,08h        ;use INT 8,
  228.     mov    ah,18        ;ticks per sec
  229.     mov    dx,55        ;millisec/tick
  230.     ret
  231. ;
  232. ;The end of our program.
  233. ;
  234. endcode label byte
  235.  
  236. code    ends
  237.  
  238.     end    main
  239.